package socket.chat;

import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.net.Socket;
import java.net.UnknownHostException;
import java.util.Scanner;

public class Client {
	public static void main(String[] args) {
		try {
			@SuppressWarnings("resource")
			Socket socket = new Socket("192.168.1.104",8088);//请求建立连接
			new Thread(new Runnable() {				
				@Override
				public void run() {
					ObjectInputStream in;
					try {
						while(true){
						in=new ObjectInputStream(socket.getInputStream());
						Object[] o=(Object[]) in.readObject();						
						System.out.println(o[0]+""+o[1]);
						}
					} catch (IOException e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					} catch (ClassNotFoundException e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					}
				}
			}).start();
			@SuppressWarnings("resource")
			Scanner kb=new Scanner(System.in);
			String s;
			ObjectOutputStream out=new ObjectOutputStream(socket.getOutputStream());
			do {
				s=kb.nextLine();
				out.writeObject(s);
				out.flush();
			} while (!s.equals("bye"));
		} catch (UnknownHostException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}
